<?php
// +----------------------------------------------------------------------
// | Author: 发仔 <i@fazi.me> 
// +----------------------------------------------------------------------

namespace app\html\controller;

use think\Db;
use think\Env;
use think\Request;
use app\open\model\Menu;
class Base extends \app\base\controller\Base
{
    public $setting;#系统配置

	public function _initialize()
    {
        //配置
        $this->setting = Db::name('setting')->column('val','key');
        $this->setting['api_host'] = Env::get('api.host');#API前缀 http开头
        $this->setting['api_redirect'] = Env::get('api.redirect');#跳转地址 http开头
        $this->assign('setting',$this->setting);
        //当前页面名称
        $request = Request::instance();
        $this->assign('current_pos', $request->pathinfo() );

        //当前用户菜单
        if(!empty($_COOKIE['user'])) {
            $user = json_decode($_COOKIE['user'],1);
            if($user['user_id']) {
                $list = (new Menu())->user($user['user_id']);
                //生成HTMl
                $html = "";
                foreach ( $list AS $first_key => $first_value) {
                	
                    $html .= " <li class='layui-nav-item'><a class='{$first_key['url']}' href='javascript:;'>{$first_value['name']}</a>";
                    if($first_value['children']) {
                        $html .= "<dl class='layui-nav-child'>";
                        foreach($first_value['children'] AS $second_key => $second_value) {
                            $second_value['mode'] == 1 && $html .= "<dd><a href='{$second_value['url']}'>{$second_value['name']}</a></dd>";
                        }
                        $html .= "</dl>";
                    }
                    $html .= "</li>";
                }
                $this->assign('menu',$html);
            }
        }
    }

}
